import request from "@/utils/request";
// import store from "@/store";

//请求--登陆
export const login = (data) => {
    return request({
        url: '/v1_0/authorizations',
        method: 'post',
        data,
    })
}

//请求--验证码
export const sendCode = (phone) => {
    return request({
        url:`/app/v1_0/sms/codes/:${phone}`,
        method: 'get',
    })
}

//请求--用户数据
export const gitUserInfo = () => {
    return request({
        url:`/v1_0/user`,
        method: 'get',
    })
}

//请求--编辑用户数据
export const changeUserInfo = (data) => {
    return request({
        url:`/v1_0/user/profile`,
        method: 'PATCH',
        data
    })
}

//请求--编辑用户照片 头像
export const changeUserPhoto = (data) => {
    return request({
        url:`/v1_0/user/photo`,
        method: 'PATCH',
        headers:{
            "Content-Type":"multipart/form-data",
            // "Authorization":store.state.user.token
        },
        data
    })
}

//请求--用户个人资料
export const gitUserInfoProfile = () => {
    return request({
        url:`/v1_0/user/profile`,
        method: 'get',
    })
}

//请求--用户频道列表
export const gitChannels = () => {
    return request({
        url:`/v1_0/user/channels`,
        method: 'get',
    })
}

//请求--所有频道列表
export const gitAllChannels = () => {
    return request({
        url:`/v1_0/channels`,
        method: 'get',
    })
}

//请求--添加用户频道
export const addUserChannels = (channels) => {
    return request({
        url:`/v1_0/user/channels`,
        method: 'patch',
        data:{
            channels:[channels],
        }
    })
}

//请求--删除用户频道
export const deletedUserChannels = (id) => {
    return request({
        url:`/v1_0/user/channels`,
        method: 'delete',
        data:{
            channels:[id]
        },
    })
}

//请求--频道内文章
export const getArticles = (params) => {
    return request({
        url:`/v1_0/articles`,
        method: 'get',
        params
    })
}

//请求--联想建议
export const getSearchSuggestion = (q) => {
    return request({
        url:`/v1_0/suggestion`,
        method: 'get',
        params:{
            q,
        },
    })
}

//请求--搜索结果
export const getSearchResult = params => {
    return request({
        url:`/v1_0/search`,
        method: 'get',
        params,
    })
}

//请求--搜索结果
export const getArticleDetail = id => {
    return request({
        url:`/v1_0/articles/${id}`,
        method: 'get',
    })
}


//请求--关注用户
export const onFollowUser = id => {
    return request({
        url:`/v1_0/user/followings`,
        method: 'post',
        data:{
            target:id,
        }
    })
}

//请求--取消关注
export const cancelFollowUser = id => {
    return request({
        url:`/v1_0/user/followings/${id}`,
        method: 'delete',
    })
}

//请求--收藏文章
export const collectArticle = id => {
    return request({
        url:`/v1_0/article/collections`,
        method: 'post',
        data:{
            target:id,
        }
    })
}

//请求--取消收藏
export const cancelCollect = id => {
    return request({
        url:`/v1_0/article/collections/${id}`,
        method: 'delete',
    })
}

//请求--点赞文章
export const onLikeArticle = id => {
    return request({
        url:`/v1_0/article/likings`,
        method: 'post',
        data:{
            target:id,
        }
    })
}

//请求--取消点赞
export const cancelLikeArticle = id => {
    return request({
        url:`/v1_0/article/likings/${id}`,
        method: 'delete',
    })
}

//请求--获取评论 或 评论回复
export const getComments = params=>{
    return request({
        url:`/v1_0/comments`,
        method:'get',
        params,
    })
}

//请求--评论点赞
export const commentLike = id => {
    return request({
        url:`/v1_0/comment/likings`,
        method:'POST',
        data:{
            target:id//.toString()
        }
    })
}

//请求--取消评论点赞
export const cancelCommentLike = id => {
    return request({
        url:`/v1_0/comment/likings/${id}`,
        method: 'DELETE',
    })
}

//请求--评论点赞
export const CommentOrReply = data => {
    return request({
        url:`/v1_0/comments`,
        method:'POST',
        data,
    })
}

